package com.xzit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xzit.entity.Channel;
import com.xzit.service.IChannelService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 栏目表 前端控制器
 * </p>
 *
 * @author zouyu
 * @since 2025-08-05
 */
@RestController
@RequestMapping("/channel")

public class ChannelController {
    @Resource
    private IChannelService channelService;

    @Operation(summary = "添加栏目")
    @PostMapping("/add")
    public void add(@RequestBody Channel channel) {
        channel.setDeleted(false); // 明确设置为未删除
        channelService.save(channel);
    }

    @Operation(summary = "根据ID删除栏目（逻辑删除）")
    @DeleteMapping("/{id}")
    public boolean deleteChannel(@PathVariable Integer id) {
        return channelService.removeById(id);
    }

    @Operation(summary = "查询所有栏目")
    @GetMapping("/list")
    public List<Channel> listChannels() {
        return channelService.list();
    }

    @Operation(summary = "根据ID查询栏目")
    @GetMapping("/{id}")
    public Channel getChannelById(@PathVariable Integer id) {
        return channelService.getById(id);
    }

    @Operation(summary = "分页查询栏目")
    @GetMapping("/page")
    public Page<Channel> pageChannels(
            @RequestParam int pageNum,
            @RequestParam int pageSize) {
        Page<Channel> page = new Page<>(pageNum, pageSize);
        return channelService.page(page);
    }


}
